﻿package Common 
{
	import flash.display.GradientType;
	import flash.display.InterpolationMethod;
	import flash.display.SpreadMethod;
	import flash.display.Sprite;
	import flash.filters.DropShadowFilter;
	import flash.geom.Matrix;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	import Fonts.CalibriEmbed;
	
	/**
	 * ...
	 * @author Serg de Adelantado
	 */
	public class AbstractMessage extends Sprite 
	{
		protected var FFormat:TextFormat;
		protected var FWidth:int;
		protected var FHeight:int;		
		protected var FHeadrer:TextField;
		protected var FText:TextField;
		
		public function AbstractMessage() 
		{
			SetSizes();
			DrawBackground([Constants.MESSAGE_BACKGROUND, 0x999999])
			filters = [new DropShadowFilter(0, 0, 0, 1, 15, 15, 1, 3)];
			FHeadrer = new TextField();
			FFormat = new TextFormat();
			var vFont:CalibriEmbed = new CalibriEmbed();
			FFormat.font = vFont.fontName;
			FFormat.size = 17;
			FFormat.align = TextFormatAlign.CENTER;
			
			FHeadrer.selectable = false;
			FHeadrer.mouseEnabled = false;			
			FHeadrer.defaultTextFormat = FFormat;			
			FHeadrer.text = 'Заголовок';
			
			FText = new TextField();
			FText.selectable = false;
			FText.mouseEnabled = false;
			FText.multiline = true;
			FText.wordWrap = true;
			FFormat.align = TextFormatAlign.LEFT;
			FFormat.size = 14;
			FText.defaultTextFormat = FFormat;			
			FText.text = 'Текст';
				
			FHeadrer.textColor = Constants.MESSAGE_HEADER_COLOR;
			addChild(FHeadrer);
			addChild(FText);
		}
		
		protected function SetSizes():void
		{
			FWidth = 0;
			FHeight = 0;			
		}		
		
		protected function DrawBackground(AColors:Array):void
		{			
			var vFillType:String = GradientType.LINEAR;
			var vAlphas:Array = new Array();
			for(var i in AColors)
				vAlphas.push(Constants.MESSAGE_BACKGROUND_ALPHA);
			var vRatios:Array = new Array();
			vRatios.push(20);
			vRatios.push(255);
			var vSpreadMethod:String = SpreadMethod.PAD; 
			var vInterpolation:String = InterpolationMethod.LINEAR_RGB; 
			var vFocalPtRatio:Number = 0;			
			var vMatrix:Matrix = new Matrix(); 
			var vBoxWidth:Number = FWidth;
			var vBoxHeight:Number = FHeight; 
			var vBoxRotation:Number = Math.PI / 2;
			var vTx:Number = 0; 
			var vTy:Number = 0; 
			vMatrix.createGradientBox(vBoxWidth, vBoxHeight, vBoxRotation, vTx, vTy);			
			graphics.clear();
			graphics.beginGradientFill(vFillType, AColors, vAlphas, vRatios, vMatrix, vSpreadMethod, vInterpolation, vFocalPtRatio);
			graphics.drawRect(0, 0, FWidth, FHeight);
			graphics.endFill();
		}
		
		public function Resize():void 
		{			
		}
		
		public function set Description(ADescription:String):void
		{
			FText.text = ADescription;
		}
		
		public function set Header(AText:String):void
		{			
			FHeadrer.text = AText;
		}
	}
}